package com.ruoyi.sys.poster.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.sys.poster.domain.Poster;
import com.ruoyi.sys.poster.service.IPosterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 广告Controller
 * 
 * @author hyl
 * @date 2025-06-07
 */
@RestController
@RequestMapping("/poster/poster")
public class PosterController extends BaseController
{
    @Autowired
    private IPosterService posterService;

    /**
     * 查询广告列表
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:list')")
    @GetMapping("/list")
    public TableDataInfo list(Poster poster)
    {
        System.out.println("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"+poster.getBeginTime02()+poster.getEndTime02());
        startPage();
        List<Poster> list = posterService.selectPosterList(poster);
        return getDataTable(list);
    }

    /**
     * 导出广告列表
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:export')")
    @Log(title = "广告", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Poster poster)
    {
        List<Poster> list = posterService.selectPosterList(poster);
        ExcelUtil<Poster> util = new ExcelUtil<Poster>(Poster.class);
        util.exportExcel(response, list, "广告数据");
    }

    /**
     * 获取广告详细信息
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:query')")
    @GetMapping(value = "/{posterId}")
    public AjaxResult getInfo(@PathVariable("posterId") Long posterId)
    {
        return success(posterService.selectPosterByPosterId(posterId));
    }

    /**
     * 新增广告
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:add')")
    @Log(title = "广告", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Poster poster)
    {
        return toAjax(posterService.insertPoster(poster));
    }

    /**
     * 修改广告
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:edit')")
    @Log(title = "广告", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Poster poster)
    {
        return toAjax(posterService.updatePoster(poster));
    }

    /**
     * 删除广告
     */
    @PreAuthorize("@ss.hasPermi('poster:poster:remove')")
    @Log(title = "广告", businessType = BusinessType.DELETE)
	@DeleteMapping("/{posterIds}")
    public AjaxResult remove(@PathVariable Long[] posterIds)
    {
        return toAjax(posterService.deletePosterByPosterIds(posterIds));
    }
}
